using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using NET.Library.Types;
//using NET.Library.Data;

namespace NET.Library.Web.Forms.DataControls.Repeaters
{
    /// <summary>
    /// Populate variable types with values from Repeater control data items.
    /// </summary>
    public class RepeaterDataItems
    {
        /// <summary>
        /// Return Repeater control data item as a string type.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static string StringDataItem(string fieldName, RepeaterItemEventArgs e)
        {
            return DataBinder.Eval(e.Item.DataItem, fieldName).ToString();
        }

        /// <summary>
        /// Return Repeater control data item as a DateTime type.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static DateTime DateTimeDataItem(string fieldName, RepeaterItemEventArgs e)
        {
            return (DateTime)DataBinder.Eval(e.Item.DataItem, fieldName);
        }

        /// <summary>
        /// Return Repeater control data item as an integer type.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static int IntDataItem(string fieldName, RepeaterItemEventArgs e)
        {
            return (int)DataBinder.Eval(e.Item.DataItem, fieldName);
        }

        /// <summary>
        /// Return Repeater control data item used as an Image type.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static byte[] ImageDataItem(string fieldName, RepeaterItemEventArgs e)
        {
            return (byte[])DataBinder.Eval(e.Item.DataItem, fieldName);
        }

        /// <summary>
        /// Return Repeater control data item used as a Boolean type.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static bool BoolDataItem(string fieldName, RepeaterItemEventArgs e)
        {
            return Booleans.boolGetValue(DataBinder.Eval(e.Item.DataItem, fieldName));
            //return DBHelper.boolValue(DataBinder.Eval(e.Item.DataItem, fieldName));
        }
    }
}
